<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>均线策略</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css">
    <script src="/static/layui/layui.js"></script>
    <script src="/static/js/jquery.js"></script>
    <style>
        .header {
            height: 100px;
            text-align: center;
            line-height: 100px;
        }

        .my_form {
            width: 800px;
            margin: 15px auto;
        }
    </style>
</head>
<body>
<div class="header">
    单日均线策略
</div>
<div class="my_form">
    <form class="layui-form" method="post" action="/ma/strategy/" lay-filter="example">
        {% csrf_token %}
        <div class="layui-form-item">
            <label class="layui-form-label">股票代号</label>
            <div class="layui-input-block">
                <input type="text" name="stockcode" lay-verify="title" autocomplete="off" placeholder="请输入股票代号"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">均线周期</label>
            <div class="layui-input-block">
                <input type="text" name="ma" lay-verify="title" autocomplete="off" placeholder="请输入均线周期"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">起始日期</label>
            <div class="layui-input-inline">
                <input type="text" name="startdate" id="startdate" lay-verify="date" placeholder="yyyy-MM-dd"
                       autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">初始资金</label>
            <div class="layui-input-block">
                <input type="text" name="money" lay-verify="title" autocomplete="off" placeholder="请输入初始资金"
                       class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
            </div>
        </div>
    </form>
</div>
<script>
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;

        //日期
        laydate.render({
            elem: '#startdate'
        });

        //监听提交
{#        form.on('submit(demo1)', function (data) {#}
{#            $.ajax({#}
{#                    type: 'post',#}
{#                    url: '/ma/strategy/',#}
{#                    data: data.field,#}
{#                    dataType: 'json',#}
{#                    success: function (data) {#}
{#                        //console.log(data);#}
{#                        //console.log(data.error)#}
{#                        if (data.error) {#}
{#                            layer.alert(data.error);#}
{#                        } else {#}
{#                            layer.alert(data.sum_rate, {#}
{#                                icon: 6#}
{#                            });#}
{#                        }#}
{#                    }#}
{#                }#}
{#            );#}
{#            return false;#}
{#        });#}

        //表单初始赋值
        form.val('example', {
            "stockcode": "^IXIC", // "name": "value"
            "ma": 120,
            "money": 10000
        })
    });
</script>
</body>
</html>